<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件生命周期（旧）</title>
</head>
<body>
    <div id="app"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入babel -->
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">
        class A extends React.Component {
            // 自定义状态
            state = {number:0}

            // 自定义事件
            death = () => {
                // 卸载组件
                ReactDOM.unmountComponentAtNode(document.querySelector('#app'))
            }
            add = ()=>{
                let {number} = this.state
                this.setState({number:number+1})
            }
            updata = ()=>{
                this.forceUpdate()
            }

            render() {
                console.log('A','render');
                return (
                    <div id="">
                        <B number={this.state.number}/>
                        <button onClick={this.death}>卸载组件</button>
                        <button onClick={this.add}>加一</button>
                        <button onClick={this.updata}>强制更新</button>
                    </div>
                )
            }
        }

        class B extends React.Component {
            // 子组件将要接收props
            componentWillReceiveProps() {
                console.log('B','componentWillReceiveProps');
            }
            // 组件是否要更新
            shouldComponentUpdate() {
                console.log('shouldComponentUpdata');
                return true
            }
            // 组件将要更新
            componentWillUpdate() {
                console.log('componentWillUpdate');
            }
            // 组件更新完毕
            componentDidUpdate() {
                console.log('componentDidUpdate');
            }
            render() {
                console.log('B','render');
                return (
                    <h1>子组件： {this.props.number}</h1>
                )
            }
        }
        ReactDOM.render(<A/>,document.querySelector("#app"))

    </script>
</body>
</html>